<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/7
 * Time: 21:19
 */

namespace app\api\service;


use app\api\model\User;

class RecyclePaidMessage extends WxMessage
{
    const tmpID = 'UMZyPItM8H_lGYNiknYHkSOf5zhOUJawyfeDn4ZK_eM';
    const pagePath = '/pages/my/my';


    public function sendMsg($order){
        $this->touser = $this->getOpenID($order->user_id);
        $this->template_id = self::tmpID;
        $this->page = self::pagePath;
        // prepay_id 暂存 from_id
        $this->form_id = $order->prepay_id;
        $this->data = $this->getData($order);
        return parent::sendToUser();
    }

    private function getData($order){
        $date = new \DateTime();
        // $data = [
        //     'keyword1' => ['value' => $order->total_price],
        //     'keyword2' => ['value'=> "卖书订单款"],
        //     'keyword3' => ['value'=> $date->format("Y-m-d H:i")],
        //     'keyword4' => ['value'=> $order->total_no],
        //     'keyword5' => ['value'=> $order->snap_name]
        // ];

        // $cds = $order->total_price;

        $array = [
            'keyword1' => [
                'value' => $order->total_price
            ],
            'keyword2' => [
                'value' => '卖书订单款'
            ],
            'keyword3' => [
                'value' => $date->format("Y-m-d H:i")
            ],
            'keyword4' => [
                'value' => $order->order_no
            ],
            'keyword5' => [
                'value' => $order->snap_name
            ]
        ];
        return $array;
    }

    private function getOpenID($uid){
        $user = User::get($uid);
        return $user->openid;
    }
}